﻿using System;
using System.Configuration;
using DFT.DB;
using DFT.Infos;

namespace DFT.AJAX
{
    public partial class UpdateUserData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String newFullName = Request.Form["newFullName"];
            String newEmail = Request.Form["newEmail"];
            String returnCdoe = "";

            if (DBManager.UpdateUserData(((UserInfo)Session["userInfo"]).UserId, newFullName, newEmail, ref returnCdoe))
            {
                if (returnCdoe == "0")
                {
                    UserInfo userInfo = new UserInfo();
                    userInfo = (UserInfo)Session["userInfo"];
                    userInfo.FullName = newFullName;
                    userInfo.Email = newEmail;
                    Session["userInfo"] = userInfo;
                    if (Boolean.Parse(ConfigurationManager.AppSettings["MailEnabled"]))
                    {
                        //String templatePath = HttpContext.Current.Server.MapPath("~//EmailTemplates//ResetPassword.htm");
                        //String body = File.ReadAllText(templatePath);
                        //body = body.Replace("@Name", fullName);
                        //body = body.Replace("@Email", userEmail);
                        //body = body.Replace("@Password", newPassword);
                        //MailHelper.SendMailMessage(userEmail, "sub", body);
                    }
                }
            }
            Response.Write(returnCdoe);
        }
    }
}